﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Ex6.ExtractEmail
{
    class ExtractEmail
    {
        public static void ExtractEmails(string text)
        {
            string expression = @"(\s*\w+@(\w+\.)+\w{2,4}\s*)";
            //string expression2 = @"^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$";

            Regex regex = new Regex(expression, RegexOptions.IgnoreCase);

            MatchCollection match = regex.Matches(text);

            if (match.Count > 0)
            {
                Console.Write("E-mails: ");
                foreach (var word in match)
                {
                    Console.Write("\"{0}\", ", word);
                }
            }
            else
            {
                Console.WriteLine("No e-mails were found!");
            }
            Console.WriteLine();
        }
        static void Main(string[] args)
        {
            string text = "This is some textalab: ala@abv.bg i posleeee portokala men@men.men.bg ";
            ExtractEmails(text);
        }
    }
}
